namespace study04 {
    function addUser(a: string, b: string): void {
        console.log(`${a}-${b}`);

    }
    addUser('zhichao', '666')


    // 书写完整的函数类型
    let addUser2: (a: string, b: string) => void
        = function (a: string, b: string): void {
            console.log(`${a}+${b}`);
        }
    addUser2('zhichao', '666')

    let sumNum: (pre: number, cur: number) => number
        = function (num1, num2) {
            return num1 + num2
        }
    console.log(sumNum(23, 32));

    let arra = [12, 45, 65,]
    arra.forEach(item => {

    })
    console.log(arra.concat(78, 23, 12));
    // let numarr


    // 可选值
    function addUser3(a: string, b?: string | undefined): void {
        console.log(`${a}-${b || '967'}`);

    }
    addUser3('志超')

    let sumNum4: (pre: number, cur?: number | undefined) => number
        = function (per, cur) {
            // let c = cur || 0
            return per + (cur || 0)
        }

    // 函数参数的默认值 通过默认值的方式解决undefined 不匹配问题
    const fn: (name?: string) => string = (name: string = "我是默认值"): string => {
        return name
    }
    console.log(fn()); // 我是默认值


    // 定义剩余参数
    interface InterArray {
        [index: number]: undefined | string
    }
    const fn2 = (a: number, ...items: string[]): InterArray => {
        return items
    }
    fn2(123, 'wr', 'wer', '234')


    // 返回对象

    interface IfnRes {
        name: string
        age: number
    }

    const fn3: (name: string, age: number) => IfnRes = (name, age) => {
        return {
            name: 'chao',
            age: 12
        }
    }



}